<template>
  <a-modal
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-descriptions :title="formInfo.title">

      <a-descriptions-item label="发布人">{{ formInfo.createBy }}</a-descriptions-item>
      <a-descriptions-item label="发布时间">{{ formInfo.createTime }}</a-descriptions-item>
      <a-descriptions-item label="类型">
        {{ this.$sysDictFilter(formInfo.msgCategory, 'msgCategory') }}
      </a-descriptions-item>
      <a-descriptions-item label="优先级" span="3">
        {{ this.$sysDictFilter(formInfo.priority, 'priority') }}
      </a-descriptions-item>
      <a-descriptions-item label="内容">
        <div v-html="formInfo.content"></div>
      </a-descriptions-item>
    </a-descriptions>
  </a-modal>
</template>

<script>
  import pick from 'lodash.pick'
  import { getAction } from '@/api/manage'

  export default {
    name: 'NoticeView',
    components: {},
    data () {
      return {
        visible: false,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        confirmLoading: false,
        formInfo: {},
        url: {
          getInfo: '/system/sysNotice/myNoticeView'
        }
      }
    },
    created () {
    },
    methods: {
      show (record) {
        this.$objToOverride(this.formInfo, record)
        if (this.formInfo.sncId) {
          getAction(this.url.getInfo, { 'sncId': record.sncId }).then(res => {
            this.$nextTick(() => {
              this.formInfo = (pick(res.result.data, 'id', 'title', 'msgCategory', 'shorter', 'content', 'priority', 'createBy', 'createTime'))
            })
          })
        }
        this.visible = true
      },
      showRouter(record){
         getAction(this.url.getInfo, { 'sncId': record.id }).then(res => {
           this.$nextTick(() => {
            var param = JSON.parse(record.param);
            param.time=new Date().getTime();
            this.$router.push({ name: record.router, query:param});
           })
         })
      },
      // 确定
      handleSubmit () {
        this.$emit('ok')
        this.visible = false
      },
      // 关闭
      handleCancel () {
        this.$emit('ok')
        this.close()
      },
      close () {
        this.$emit('ok')
        this.visible = false
      }
    }
  }
</script>
